from selenium.webdriver.firefox.webdriver import WebDriver
from locators import ProfileLocators
from pages.base import BasePage
import pages


class ProfilePage(BasePage):

    def __init__(self, driver: WebDriver):
        super().__init__(driver)

    def back_to_account_list(self):
        self.back()
        self.wait_new_page(pages.AccountListPage.URL)
        return pages.AccountListPage(self.driver)

    def logout(self):
        user_icon = self.find_element(ProfileLocators.USER_ICON_LOCATOR)
        user_icon.click()
        logout_btn = self.find_element(ProfileLocators.LOGOUT_LOCATOR)
        logout_btn.click()

        return pages.AuthorizationPage(self.driver)

    def get_login_text(self):
        return self.find_element(ProfileLocators.LOGIN_LOCATOR).text

    def get_lastname_text(self):
        return self.find_element(ProfileLocators.LASTNAME_LOCATOR).text

    def get_firstname_text(self):
        return self.find_element(ProfileLocators.FIRSTNAME_LOCATOR).text
